home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
bbs
/
doorinfo.zip
/
PLAYXWIT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-14
|
17KB
|
628 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include "doorutil.h"
#include "croswits.h"
void show_games(void);
char hello[] =
"Welcome to CROSWITS!\r\r"
"This is a word game, based on the familiar SCRABBLE game.\r"
"This program is copyright by Herb Rose, 1995.\r\r";
char active[] =
"Entering FALKEN CROSWITS!\r\r"
"Type 'help' for an explanation of the game and a help screen.\r"
"The game is like a mini-teleconference, so you can talk to the\r"
"other players.\r";
struct game_rec game, game2;
struct board_rec board2[15][15] =
{
'_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, TW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW,
'_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
'_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, DL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, DL,
'_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DW, '_', 0, NL, '_', 0, NL, '_', 0, NL,
'_', 0, TL, '_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, TL,
'_', 0, NL, '_', 0, NL, '_', 0, NL, '_', 0, DW, '_', 0, NL,
'_', 0, TW, '_', 0, NL, '_', 0, NL, '_', 0, DL, '_', 0, NL,
'_', 0, NL, '_', 0, NL, '_', 0, TW, '_', 0, NL, '_', 0, NL,
'_', 0, NL, '_', 0, DL, '_', 0, NL, '_', 0, NL, '_', 0, TW
};
struct letter_rec BASE_letters[NUMLETTERS] =
{
'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0,
'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'A', 1, 0, 'B', 3, 0,
'B', 3, 0, 'C', 3, 0, 'C', 3, 0, 'D', 2, 0, 'D', 2, 0,
'D', 2, 0, 'D', 2, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0,
'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0,
'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'E', 1, 0, 'F', 4, 0,
'F', 4, 0, 'G', 2, 0, 'G', 2, 0, 'G', 2, 0, 'H', 4, 0,
'H', 4, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0,
'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0, 'I', 1, 0,
'J', 8, 0, 'K', 5, 0, 'L', 1, 0, 'L', 1, 0, 'L', 1, 0,
'L', 1, 0, 'M', 3, 0, 'M', 3, 0, 'N', 1, 0, 'N', 1, 0,
'N', 1, 0, 'N', 1, 0, 'N', 1, 0, 'N', 1, 0, 'O', 1, 0,
'O', 1, 0, 'O', 1, 0, 'O', 1, 0, 'O', 1, 0, 'O', 1, 0,
'O', 1, 0, 'O', 1, 0, 'P', 3, 0, 'P', 3, 0, 'Q', 10, 0,
'R', 1, 0, 'R', 1, 0, 'R', 1, 0, 'R', 1, 0, 'R', 1, 0,
'R', 1, 0, 'S', 1, 0, 'S', 1, 0, 'S', 1, 0, 'S', 1, 0,
'T', 1, 0, 'T', 1, 0, 'T', 1, 0, 'T', 1, 0, 'T', 1, 0,
'T', 1, 0, 'U', 1, 0, 'U', 1, 0, 'U', 1, 0, 'U', 1, 0,
'V', 4, 0, 'V', 4, 0, 'W', 4, 0, 'W', 4, 0, 'X', 8, 0,
'Y', 4, 0, 'Y', 4, 0, 'Z', 10, 0, '?', 0, 0, '?', 0, 0
};
char wb[200];
ENTRY mkey;
char scrabname[80];
struct acct_rec ac;
struct xwit_player_rec aplayer;
char unreg_text[] =
"This version of CROSWITS is unregistered, and limited to 5 games.\r"
"You may not start a new game.\r\r"
"To remedy this situation, please ask your SYSOP to register the game.\r\r";
int registered = 0;
int dbfile;
main()
{
int k, j, n, status, size, done;
int gamect;
time_t t1;
char *cp;
init();
t1 = time(NULL);
send(hello);
registered = check_registration("CROSWITS", 19866);
if (!registered)
qputs("\rThis version of CROSWITS is NOT REGISTERED.\r");
if (myuser->u_ansi == 0)
{
send("You must have ANSI turned on to play this game.\r");
exit(0);
}
for (;;)
{
strcpy(myuser->doors_id, "playxwit");
gamect = 0;
myuser->u_work1 = -1; /* don't show that we are in a game. */
j = 0;
dbfile = btrv(b_open, -1, "croswits.idx", &j, (ENTRY *) "croswits.dat", 1);
if (dbfile != -1)
{
size = sizeof(struct xwit_player_rec);
sprintf(mkey.key, "!%s", myacct->acctname);
if ((status = btrv(b_getequ, dbfile, &aplayer, &size, &mkey, 0)) == OK)
{
for (n = 0; n < 40; n++)
{
if (aplayer.games[n] > 0)
{
size = sizeof(struct game_rec);
sprintf(mkey.key, "%05d", aplayer.games[n]);
status = btrv(b_getequ, dbfile, &game, &size, &mkey, 0);
if ((status == OK) && (gamect < 40))
{
if ((game.game_end_time != (time_t) 0) &&
((t1 - game.game_end_time) > (time_t) (7L * 3600L * 24L)))
{
btrv(b_delete, dbfile, &game, &size, &mkey, 0);
}
else if (game.player[0].name[0] == '\0' &&
game.player[1].name[0] == '\0' &&
game.player[2].name[0] == '\0' &&
game.player[3].name[0] == '\0')
{
btrv(b_delete, dbfile, &game, &size, &mkey, 0);
}
else
{
if ((strcmpi(game.player[0].name, myacct->acctname) == 0) ||
(strcmpi(game.player[1].name, myacct->acctname) == 0) ||
(strcmpi(game.player[2].name, myacct->acctname) == 0) ||
(strcmpi(game.player[3].name, myacct->acctname) == 0))
{
if (gamect == 0)
{
send("Games you are currently playing :\r");
}
gamect++;
sprintf(wb, " Game %d with ", atoi(mkey.key));
for (j = 0; j < MAXPLAYERS; j++)
{
if (strlen(game.player[j].name) &&
strcmpi(myacct->acctname, game.player[j].name))
{
strcat(wb, game.player[j].name);
strcat(wb, ", ");
}
}
if (game.game_end_time != 0L)
{
strcat(wb, " GAME OVER.\r");
}
else
{
strcat(wb, " it is ");
strcat(wb, game.player[game.whose_turn].name);
strcat(wb, "'s turn.\r");
}
send(wb);
}
}
}
else
{
aplayer.games[n] = 0;
}
}
}
}
btrv(b_close, dbfile, &game, &size, &mkey, 0);
}
for (done = 0; done == 0;)
{
if (gamect)
{
send("\rEnter the game number to join, or 'NEW' for a new game,\r");
}
else
{
send("You have no active games. Enter 'NEW' to start a new game,\r");
}
send("or, enter 'LIST' to see all the active games,\r");
if (myacct->accessflags & sysopaccess)
{
send("or, enter 'DELETE x' to delete game number 'x', \r");
}
send("or, enter 'QUIT' if you choose not to play now.\r\r?");
qgets(wb, 80);
if (wb[0] == 'q')
exit(0);
else if (wb[0] == 'l')
show_games();
else if (wb[0] == 'n')
{
done = 1;
j = -1;
}
else if (strnicmp("del", wb, 3) == 0)
{
if (myacct->accessflags & sysopaccess)
{
cp = strtok(wb, " ,");
cp = strtok(NULL, " ,");
if (cp == NULL)
{
send("Format for delete is 'delete #'.\r");
}
else
{
j = atoi(cp);
delete_game(j);
}
}
else
{
send("Only sysops can delete games.\r");
}
}
else if (isdigit(wb[0]))
{
j = atoi(wb);
if (j > 0)
{
for (k = 0; k < 40; k++)
{
if (aplayer.games[k] == j)
{
done = 1;
break;
}
}
}
}
}
if (j == -1)
{
for (j = 0; ((j < 40) && (aplayer.games[j] > 0)); j++);
if (j == 40)
{
send("Too many games. You cannot start a new CROSWITS game.\r");
continue; /* continue the for(ever) type loop */
}
memset(&game, 0, sizeof(struct game_rec));
memcpy(game.letters, BASE_letters, sizeof(BASE_letters));
memcpy(game.board, board2, sizeof(board2));
for (j = 0; j < MAXPLAYERS; j++)
{
game.player[j].line_num = -1;
}
game.letters_left = NUMLETTERS;
game.game_start_time = time(NULL);
game.game_end_time = (time_t) 0;
strcpy(game.player[0].name, myacct->acctname);
send("Please enter the names of the users who will be playing this\r");
send("game with you. Up to 3 other players are allowed.\r");
send("Press [ENTER] after each name, and press [ENTER] on a blank\r");
send("line when done with the entries.\r");
do
{
send("\rPlayer 1 : ");
qgets(wb, 80);
if (strlen(wb) == 0)
exit(0);
if ((status = find_account(wb, &ac)) != OK)
{
send("No account for that name.\r");
}
for (j = 0; j < MAXPLAYERS; j++)
{
if (strcmpi(ac.acctname, game.player[j].name) == 0)
{
send("That player is already in the game.\r");
status = (!OK);
}
}
} while (status != OK);
strcpy(game.player[1].name, ac.acctname);
do
{
send("\rPlayer 2 : ");
qgets(wb, 80);
if (strlen(wb) == 0)
break;
if ((status = find_account(wb, &ac)) != OK)
{
send("No account for that name.\r");
}
for (j = 0; j < MAXPLAYERS; j++)
{
if (strcmpi(ac.acctname, game.player[j].name) == 0)
{
send("That player is already in the game.\r");
status = (!OK);
}
}
} while (status != OK);
if (strlen(wb) != 0)
{
strcpy(game.player[2].name, ac.acctname);
do
{
send("\rPlayer 3 : ");
qgets(wb, 80);
if (strlen(wb) == 0)
break;
if ((status = find_account(wb, &ac)) != OK)
{
send("No account for that name.\r");
}
for (j = 0; j < MAXPLAYERS; j++)
{
if (strcmpi(ac.acctname, game.player[j].name) == 0)
{
send("That player is already in the game.\r");
status = (!OK);
}
}
} while (status != OK);
if (strlen(wb) != 0)
{
strcpy(game.player[3].name, ac.acctname);
}
}
srand((int) time(NULL));
do
{
j = rand() % MAXPLAYERS;
} while (strlen(game.player[j].name) == 0);
game.whose_turn = j;
for (j = 0; j < 7; j++)
{
for (k = 0; k < MAXPLAYERS; k++)
{
if (strlen(game.player[k].name))
{
do
{
status = rand() % NUMLETTERS;
} while (game.letters[status].used);
game.letters[status].used = 1;
game.player[k].letters[j] = status;
game.letters_left--;
}
}
}
if (save_new_game() == 0)
{
qputs("Error creating new game!");
exit(0);
}
j = game.game_number;
if (strlen(game.player[0].name))
setplayer(game.player[0].name, game.game_number);
if (strlen(game.player[1].name))
setplayer(game.player[1].name, game.game_number);
if (strlen(game.player[2].name))
setplayer(game.player[2].name, game.game_number);
if (strlen(game.player[3].name))
setplayer(game.player[3].name, game.game_number);
}
send(active); /* send a 'we are alive' to the user */
delay(1);
hog();
sprintf(scrabname, "croswits.exe %d", j);
strcpy(myuser->doors_id, "CROSWITS");
myuser->u_work1 = j;
for (j = 0; j < numlines; j++)
{
if (j != who)
{
if (user[j].u_stat == 6) /* is the guy in doors ? */
{
if ((strcmpi(user[j].doors_id, "CROSWITS") == 0) &&
(user[j].u_work1 == myuser->u_work1))
break;
}
}
}
nohog();
if (j == numlines) /* main prog not loaded yet! */
{
if ((j = load_a_door(scrabname, 5)) < 0)
{
sprintf(wb, "Cannot load FALKEN Scrabble!! Err = %d\r\r", j);
send(wb);
delay(2);
exit(0);
}
}
myuser->u_privateflag = 1; /* no 'login' messages */
suspend();
}
}
save_new_game()
{
int bfile;
int msize;
int j;
if ((bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1)) < 0)
bfile = btrv(b_create, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
if (bfile < 0)
{
send("Unable to save game in database! Code = 110\r");
return 0;
}
msize = sizeof(struct game_rec);
if (btrv(b_gethi, bfile, &game2, &msize, &mkey, 0) != OK)
{
game.game_number = 1;
}
else
{
game.game_number = atoi(mkey.key) + 1;
if (!registered && game.game_number > 5)
{
send(unreg_text);
return 0;
}
}
sprintf(mkey.key, "%05d", game.game_number);
msize = sizeof(struct game_rec);
if (btrv(b_insert, bfile, &game, &msize, &mkey, 0) != OK)
{
btrv(b_close, bfile, &game, &msize, &mkey, 0);
send("Unable to save game in database! Code = 112\r");
return 0;
}
btrv(b_close, bfile, &game, &msize, &mkey, 0);
send("New game successfully configured and stored in database.\r");
return 1;
}
void show_games()
{
int totgamect = 0;
int j;
int lines;
int status;
int msize;
int bfile;
ENTRY mkey;
bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
if (bfile < 0)
{
send("Unable to open game file for input!\r");
return;
}
msize = sizeof(struct game_rec);
strcpy(mkey.key, "00000");
status = btrv(b_getge, bfile, &game, &msize, &mkey, 0);
lines = 0;
while (status == OK)
{
totgamect++;
qprintf("Game %3d : ", game.game_number);
for (j = 0; j < MAXPLAYERS; j++)
{
if (strlen(game.player[j].name))
{
qprintf("%s (%d), ", game.player[j].name,
game.player[j].score);
}
}
qprintf(" %d letters left.\r", game.letters_left);
if (++lines == 20)
{
send("\rPress [ENTER] to continue or 'Q' to quit :");
qgets(wb, 80);
if (tolower(wb[0]) == 'q')
break;
lines = 0;
}
msize = sizeof(struct game_rec);
status = btrv(b_getnext, bfile, &game, &msize, &mkey, 0);
}
qprintf("%d games listed.\r\r", totgamect);
btrv(b_close, bfile, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
}
delete_game(int gamenum)
{
int j;
int bfile, msize;
bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
if (bfile < 0)
{
qprintf("Unable to open game file for dlete!\r");
return;
}
msize = sizeof(struct game_rec);
sprintf(mkey.key, "%05d", gamenum);
if (btrv(b_getequ, bfile, &game, &msize, &mkey, 0) != OK)
{
qprintf("Game %d not found.\r", gamenum);
}
else
{
if (btrv(b_delete, bfile, &game, &msize, &mkey, 0) == OK)
{
send("Game deleted.\r");
}
else
{
qprintf("Error deleting game %d\n", gamenum);
}
}
btrv(b_close, bfile, &game, &msize, &mkey, 0);
}
setplayer(char *s, int num)
{
int siz;
int j;
int bfile, msize;
ENTRY akey;
if ((bfile = btrv(b_open, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1)) < 0)
bfile = btrv(b_create, -1, "croswits.idx", &msize, (ENTRY *) "croswits.dat", 1);
if (bfile < 0)
{
send("Unable to save game information in database! Code = 110\r");
return;
}
sprintf(akey.key, "!%s", s);
siz = sizeof(struct xwit_player_rec);
if (btrv(b_getequ, dbfile, &aplayer, &siz, &akey, 1) != OK)
{
memset(&aplayer, 0, sizeof(struct xwit_player_rec));
sprintf(akey.key, "!%s", s);
strcpy(aplayer.name, s);
siz = sizeof(struct xwit_player_rec);
btrv(b_insert, dbfile, &aplayer, &siz, &akey, 1);
}
for (j = 0; j < 40 && aplayer.games[j]; j++);
if (j < 40)
{
aplayer.games[j] = num;
sprintf(aplayer.name, "!%s", s);
strcpy(akey.key, aplayer.name);
siz = sizeof(struct xwit_player_rec);
btrv(b_update, dbfile, &aplayer, &siz, &akey, 1);
}
btrv(b_close, bfile, &game, &msize, &mkey, 0);
}